package top.v5it.japi.plus.data.jdbc.service;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.PagingAndSortingRepository;

/**
 * @author zhanpu
 * @date 2022/8/3
 */
public interface JapiPagingAndSortingService<T, ID> {

    PagingAndSortingRepository<T, ID> getJapiRepository();

    /**
     * 采用jdbc搜索并排序
     *
     * @param sort
     * @return
     * @see Sort
     */
    default Iterable<T> searchAll(Sort sort) {
        return getJapiRepository().findAll(sort);
    }

    /**
     * 采用jdbc搜索并分页
     *
     * @param pageable
     * @return
     * @see Pageable
     */
    default Page<T> searchAll(Pageable pageable) {
        return getJapiRepository().findAll(pageable);
    }
}
